package com.lemon.core.utils;

import lombok.extern.slf4j.Slf4j;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Period;
import java.time.format.DateTimeFormatter;

/**
 * @author 李猛
 * @datetime 2023/10/10 14:30
 * @description 类对象
 */
@Slf4j
public class LocalDateUtil {
    public final static DateTimeFormatter dateFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM");
    public final static DateTimeFormatter dateFormatter2 = DateTimeFormatter.ofPattern("yyyy年MM月");
    public final static DateTimeFormatter dateFormatter3 = DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS");
    public final static DateTimeFormatter dateFormatter4 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    public final static DateTimeFormatter dateFormatter5 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
    public final static DateTimeFormatter dateFormatter6 = DateTimeFormatter.ofPattern("HH:mm:ss");
    public final static DateTimeFormatter dateFormatter7 = DateTimeFormatter.ofPattern("yyyyMMdd");
    public final static DateTimeFormatter dateFormatter8 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss:SSS");

    public static String toString(LocalDateTime localDateTime) {
        return localDateTime.format(dateFormatter4);
    }

    //比较当前时间
    public static Integer beforeYear(LocalDate localDate) {
        if (localDate == null) {
            return null;
        }
        return Period.between(localDate, LocalDate.now()).getYears();
    }
}
